package stuff;

import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;

public class FixedSizeDocument extends PlainDocument{
	
	private static final long serialVersionUID = 1L;
	private int max = 10;
	
	public FixedSizeDocument(int maxLength) {
		this.max = maxLength;
	}
	
	@Override
	public void insertString(int offs, String str, AttributeSet a)
			throws BadLocationException {
		if (str == null) return;

	    if ((getLength() + str.length()) <= max) {
	    	super.insertString(offs, str, a);
	    }
	}
	
}
